package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.exception.RequestIllegalException;
public class SeedAddrRequest extends UserShippingAddressAddRequest{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3093593456081188191L;
	
	private String openId;
	//private Integer userId = 0;
	private String realName;
	private String phone;
	private String userAddress;
	
	public SeedAddrRequest() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		super.parse(request);
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		//this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.openId = requestInfo.getParameter(ApiUrlParamEnum.openId.getParamName(),null);
		
		this.realName = requestInfo.getParameter(ApiUrlParamEnum.realName.getParamName(),"");
		if ( StringUtil.isEmpty(realName) && StringUtil.isEmpty(this.getContacts())) {
			throw new RequestIllegalException("error realName is null ");
		}
		if( StringUtil.isEmpty(realName) && !StringUtil.isEmpty(this.getContacts())) {
			this.realName = this.getContacts();
		}
		if(!StringUtil.isEmpty(realName) && StringUtil.isEmpty(this.getContacts())) {
			this.setContacts(realName);
		}
		
		this.phone=requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		if(!StringUtil.isEmpty(phone) && (phone.length() < 11 || !StringUtil.isMobilePhone(phone))){
			throw new RequestIllegalException("手机号码格式错误 :"+phone);
		}
		if(StringUtil.isEmpty(phone)) {
			this.phone = super.getContactNumber();
		}
		/*if ( StringUtil.isEmpty(phone) ) {
			throw new RequestIllegalException("error phone is null ");
		}*/
		
		this.userAddress=requestInfo.getParameter(ApiUrlParamEnum.receiveDetailInfo.getParamName(),"");
		if ( StringUtil.isEmpty(userAddress) ) {
			throw new RequestIllegalException("error userAddress is null ");
		}
	}
		

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	/*public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}*/

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getUserAddress() {
		return userAddress;
	}

	public void setUserAddress(String userAddress) {
		this.userAddress = userAddress;
	}
}
